<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    


    <script>


        var str = 'asdasdSMasdasdasdSMsdasdasdSMsadasd'

        // 循环遍历字符串判断字符串SM
        while(str.indexOf('SM') !== -1){
            // 把替换的字符串用变量接收
            var str = str.replace('SM','**')
        }
        // 打印
        console.log(str);
        
        
    </script>
</body>
</html>